package com.zjc.springboot.kafka;

import com.zjc.springboot.kafka.messages.StormMsg;
import com.zjc.springboot.kafka.producer.KafkaProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.function.StreamBridge;

@SpringBootApplication
public class KafkaMain implements CommandLineRunner {

    @Autowired
    KafkaProducer producer;

    @Autowired
    StreamBridge streamBridge;

    public static void main(String[] args) {

        SpringApplication.run(KafkaMain.class, args);
    }

    @Override
    public void run(String... args) throws Exception {

        int count = 0;
        while (true) {
            StormMsg msg = new StormMsg();
            msg.setId(count);
            msg.setName("name");
            msg.setValue("value");

            Thread.sleep(10000);
            //producer.sendMsg(msg); //stream 3.0之前
            streamBridge.send(ChannelDefinition.TEST_STORM_OUTPUT,msg);//stream 3.0之后
        }

    }
}
